﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Google.YouTube;

namespace CMSE.Extensions.Youtube
{
    class InformationExtractor
    {
        private const string YOUTUBE_APIURL = "http://gdata.youtube.com/feeds/api/videos/";
        private const string YOUTUBE_PROJECTNAME = "YouTube Video Extension";
        private const string YOUTUBE_DEVKEY = "AI39si5-Q51z0xMKkqUXzYm3jphkf-GjvMa6G0cxSOrUtWfOM_k9R4GAOA0HcoIgT9AEmtfwhNFfm8iZm59gFYZJvD_0xxi4vw";

        public Video GetVideoInformation(string videotoken)
        {
            try
            {
                Uri uri = new Uri(YOUTUBE_APIURL + videotoken);
                Video video = GetYouTubeRequestObject().Retrieve<Video>(uri);
                return video;
            }
            catch (Exception ex)
            {
                throw new ApplicationException(ex.Message, ex.InnerException);
            }
        }

        private YouTubeRequest GetYouTubeRequestObject()
        {
            var youTubeRequestSettings = new YouTubeRequestSettings("YouTube Video Extension", "AI39si5-Q51z0xMKkqUXzYm3jphkf-GjvMa6G0cxSOrUtWfOM_k9R4GAOA0HcoIgT9AEmtfwhNFfm8iZm59gFYZJvD_0xxi4vw");
            return new YouTubeRequest(youTubeRequestSettings);
        }

    }
}
